import { request } from "../../request/index";
import { login } from "../../utils/asyncWX";
Page({
  data: {
    
  },

  // 获取用户token
  async handleGetUserInfo(e){
      try {
      // 1 获取用户信息
      const { encryptedData,signature,iv,rawData }=e.detail;
      // 2 获取小程序登录成功的code
      const {code}=await login();
      const loginParams={ encryptedData,signature,iv,rawData,code };
      // 3 发送请求 获取token
      const {token}=await request({url:"/users/wxlogin",data:loginParams,method:'post'});
      // 4 将token保存到缓存
      wx.setStorageSync('token', token);
      // 5 跳回上一页
      wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      console.log(error)
    }

  }

  
});
  